"""
ls /dev/pts/*
ps -t pts/8
ps aux | ag 6996
fcntl.ioctl(fd, request, arg=0, mutate_flag=True)
ioctl (fd, TIOCSTI, nl);
"""
import os
import glob

pts = glob.glob('/dev/pts/*')

pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]

for pid in pids:
    name = os.path.join('/proc', pid, 'fd', '0')
    if os.path.islink(name):
        link = os.readlink(name)
        if link.startswith('/dev/pts') and not link.endswith('(deleted)'):
            print(pid, link)
            print(os.getpgid(int(pid)))
            print(open(os.path.join('/proc', pid, 'cmdline')).read())
